﻿using Appliaction.AppServices.DB;
using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.DB
{
    /// <summary>
    /// 库区控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Db_warehouse_zoneController : Controller
    {
        private readonly IMapper mapper;

        private readonly IDb_warehouse_zoneServices db_warehouse_zoneService;
       
        public Db_warehouse_zoneController(IMapper _mapper, IDb_warehouse_zoneServices _db_warehouse_zoneService)
        {
            mapper = _mapper;
            db_warehouse_zoneService = _db_warehouse_zoneService;
        }

        /// <summary>
        /// 查询总条数(控制器)
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="warehouse_name"></param>
        /// <returns></returns>
        [HttpGet]
        public int warehousezoneCount(string  warehouse_code, string ? zone_name)
        {
            return db_warehouse_zoneService.Select_count_warehouse_zone(warehouse_code, zone_name);
        }

        /// <summary>
        /// 库区分页查询(控制器)
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="warehouse_name"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult WarehouseZoneFY(string warehouse_code, string ? zone_name, int currentPage, int pageSize)
        {
            return new JsonResult(db_warehouse_zoneService.Select_fy_warehouse_zone(warehouse_code, zone_name, currentPage, pageSize));
        }



        /// <summary>
        /// 仓库库区修改冻结状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="zone_freeze"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> warehouseZone_Frozenstate(int id, char zone_freeze)
        {
            return db_warehouse_zoneService.warehouse__zone_Frozenstate(id,zone_freeze); 
        }




        /// <summary>
        /// 仓库库区编码唯一性判断
        /// </summary>
        /// <param name="zone_code"></param>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> WarehousezoneCodejudgment(string zone_code, string warehouse_code)
        {

           return db_warehouse_zoneService.Warehousezone_code_judgment(zone_code, warehouse_code);
        }

        /// <summary>
        /// 仓库库区名称唯一性判断
        /// </summary>
        /// <param name="zone_name"></param>
        /// <param name="warehouse_code"></param>
        [HttpGet]
        public Task<int> WarehousezoneNamejudgment(string zone_name, string warehouse_code)
        {
            return db_warehouse_zoneService.Warehousezone_name_judgment(zone_name, warehouse_code);
        }

        /// <summary>
        /// 仓库库区添加
        /// </summary>
        /// <param name="db_WarhousezoneAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<JsonResult> WarehousezoneAdd([FromBody]Db_warhousezoneAddDto db_WarhousezoneAddDto)
        {
            return new JsonResult(await db_warehouse_zoneService.Warehousezone_Add(db_WarhousezoneAddDto));
        }


        /// <summary>
        /// 仓库库区点击允许产品混放
        /// </summary>
        /// <param name="id"></param>
        /// <param name="zone_mixing"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Warehousezone_ProductMix(Db_Warehouse_zone_UpdateDto db_Warehouse_zone_UpdateDto)
        {
           return db_warehouse_zoneService.Warehousezone_ProductMix(db_Warehouse_zone_UpdateDto);
        }
        /// <summary>
        /// 仓库库区点击不允许产品混放
        /// </summary>
        /// <param name="id"></param>
        /// <param name="zone_mixing"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Warehousezone_ProductMixNO(Db_Warehouse_zone_UpdateDto db_Warehouse_zone_UpdateDto)
        {
            return db_warehouse_zoneService.Warehousezone_ProductMixNO(db_Warehouse_zone_UpdateDto);
        }
        /// <summary>
        /// 仓库库区点击允许批次混放   
        /// </summary>
        /// <param name="id"></param>
        /// <param name="zone_batch_mixing"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Warehousezone_BatchMix(Db_Warehouse_zone_UpdateDto db_Warehouse_zone_UpdateDto)
        {
            return db_warehouse_zoneService.Warehousezone_BatchMix(db_Warehouse_zone_UpdateDto);
        }
        /// <summary>
        /// 仓库库区点击不允许混放
        /// </summary>
        /// <param name="id"></param>
        /// <param name="zone_batch_mixing"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Warehousezone_BatchMixNO(Db_Warehouse_zone_UpdateDto db_Warehouse_zone_UpdateDto)
        {
            return db_warehouse_zoneService.Warehousezone_BatchMixNO(db_Warehouse_zone_UpdateDto);
        }

        /// <summary>
        /// 判断仓库库区添加的容量是否超过仓库容量
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_capacity"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> WarehousezoneCapacityjudgment(string warehouse_code, int zone_capacity)
        {

            return db_warehouse_zoneService.Warehousezone_Capacity_judgment(warehouse_code, zone_capacity);
        }
        /// <summary>
        /// 仓库区修改
        /// </summary>
        /// <param name="db_warehouse_ZoneUpdatexgDto"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> WarehousezoneUpdate([FromBody]Db_warehouse_ZoneUpdatexgDto db_warehouse_ZoneUpdatexgDto) { 
        
            return db_warehouse_zoneService.Warehousezone_Update(db_warehouse_ZoneUpdatexgDto); 
        }
        /// <summary>
        /// 删除库区
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> warehouseZone_tombstone(string warehouse_code, string zone_code)
        {
            return db_warehouse_zoneService.warehouse_zone_tombstone(warehouse_code, zone_code);
        }


        /// <summary>
        /// 查询库区
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult warehouse_zoneAsync(string warehouse_code)
        {
            return new JsonResult(db_warehouse_zoneService.warehouse_zone_Async(warehouse_code));
        }


        /// <summary>
        /// 结构编码查询仓库信息
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Warehouse_zone_By_Select_Async_code(string warehouse_code, string zone_code)
        {

           return new JsonResult(db_warehouse_zoneService.Warehouse_zone_By_Select_Async_code(warehouse_code, zone_code));
        }


        /// <summary>
        /// 判断仓库库区修改的容量是否超过仓库容量
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_capacity"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Warehousezone_Capacity_judgment_update(string warehouse_code, string zone_code, int new_zone_capacity)
        {


            return db_warehouse_zoneService.Warehousezone_Capacity_judgment_update(warehouse_code, zone_code, new_zone_capacity);
        }


        /// <summary>
        /// 修改名称判断
        /// </summary>
        /// <param name="zone_name"></param>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_code"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Warehousezone_name_UpdateJudgment(string zone_name, string warehouse_code, string zone_code)
        {

            return db_warehouse_zoneService.Warehousezone_name_UpdateJudgment(zone_name, warehouse_code, zone_code);
        }
    }
}
